#include "systick.h"

static volatile uint32_t _u32Systicks = 0;

/**
* @brief    : This function will be used to initialize SysTick.
* @param    : ticks
* SystemFrequency / 1000    1ms raise interrupt
* SystemFrequency / 100000   10us raise interrupt
* SystemFrequency / 1000000 1us raise interrupt
* @retval   : None
*/
void Systick_Init(uint32_t ticks)
{
    SysTick_Config(ticks);
}

void Inc_Systicks(void)
{
    _u32Systicks ++;
}

uint32_t Get_Systick_Cnt(void)
{
    return _u32Systicks;
}

uint32_t Get_Systick_Val(void)
{
    return SysTick->VAL;
}
void Clear_Over_Flag(void)
{
    SysTick->CTRL;
}

uint32_t Get_Over_Flag(void)
{
    return SysTick->CTRL & (1 << 16);
}

void Systick_Delay(volatile uint32_t Delay)
{
    uint32_t tickstart = 0;
    tickstart = Get_Systick_Cnt();
    while ((Get_Systick_Cnt() - tickstart) < Delay)
    {
    }
}

void Suspend_Systicks(void)
{
    CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
}

void Resume_Systicks(void)
{
    SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
}
